package project.teg.games.game.gestures;

import project.teg.common.types.ScreenType;
import project.teg.configuration.Gestures;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

public class GameView extends View {

	public ScreenType currentScreen = ScreenType.WelcomeScreen;
	public GesturePath gesturePath;
	public InteractiveObject interactiveObject;
	public Path interactiveObjevtPath = new Path();
	
	public Paint tekstPaint;
	public Paint pathPaint;

	public GameView(Context context) {
		super(context);
		init();
	}

	public GameView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}
	
	private void init(){
		tekstPaint = new Paint();
		tekstPaint.setColor(Color.BLACK);
		tekstPaint.setTextSize(20);
		tekstPaint.setAntiAlias(true);
		
		pathPaint = new Paint();
		pathPaint.setDither(true);
		pathPaint.setColor(Gestures.pathColor);
		pathPaint.setStyle(Paint.Style.STROKE);
		pathPaint.setStrokeJoin(Paint.Join.ROUND);
		pathPaint.setStrokeCap(Paint.Cap.ROUND);
		pathPaint.setStrokeWidth(3);
	}

	int br = 1;
	
	@Override
	protected synchronized void onDraw(Canvas canvas) {
		if (gesturePath == null)
			gesturePath = new GesturePath(new PointF(this.getWidth(),
					this.getHeight()));
		int color;
		if (currentScreen == ScreenType.WelcomeScreen) {
			color = Color.BLUE;
			canvas.drawColor(color);
		} else if (currentScreen == ScreenType.NextLevel) {
			color = Gestures.backgroundColor;
			canvas.drawColor(color);
			gesturePath.drawCheckPoints(canvas);
			if (interactiveObject != null)
				interactiveObject.renderObject(canvas);
			
			for (CheckPointIndex ci : gesturePath.checkPointIndexes) {
				ci.render(canvas, tekstPaint);
			}
		}

		else {
			color = Color.RED;
			canvas.drawColor(color);
		}

		
		canvas.drawPath(interactiveObjevtPath, pathPaint);

		
	}

}